//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __CHANGENOTIFIER_H_
#define __CHANGENOTIFIER_H_

#include <ddk.h>
#include <fat.h>

class EventListNode
{
public:
    inline EventListNode();
    IEvent *pEvent;
    EventListNode *pNext;
};

EventListNode::EventListNode() :pEvent(NULL), pNext(NULL)
{
}

class NotifierListNode
{
public:
    inline NotifierListNode();
    struct node *pNode;
    EventListNode *pEvents;
    NotifierListNode *pNext;
};

NotifierListNode::NotifierListNode() :pNode(NULL), pEvents(NULL), pNext(NULL)
{
}

class CChangeNotifier
{
public:
    int NotifyMonitor(struct node *pChangeNode);
    int NotifyAllDirty();
    int AddMonitor(struct node *pNode, IEvent** ppRetEvent);
    int RemoveMonitor(struct node *pNode, IEvent *pEvent);
    CChangeNotifier();
    ~CChangeNotifier();
private:
    NotifierListNode * FindNode(struct node *pNode, NotifierListNode **ppPreNode);
    EventListNode *FindEvent(NotifierListNode *pNotifierNode,
            IEvent *pEvent, EventListNode **ppPreNode);
    inline void Lock();
    inline void Unlock();
private:
    NotifierListNode *m_pListHead;
    IMutex *m_lock;
};

#endif /* __CHANGENOTIFIER_H_ */
